package com.cssy.xxkj.logic.service.impl;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import com.byd.acegiext.domain.User;
import com.byd.acegiext.service.UserService;
import com.byd.acegiext.service.impl.UserServiceImpl;
import com.cssy.xxkj.basic.entity.BasicStorageInfoTestDO;
import com.cssy.xxkj.basic.entity.BasicStorageInfoTypeTestDO;
import com.cssy.xxkj.basic.service.IBasicStorageInfoTestService;
import com.cssy.xxkj.basic.service.IBasicStorageInfoTypeTestService;
import com.cssy.xxkj.logic.contants.BillTypeConstant;
import com.cssy.xxkj.logic.contants.Constants;
import com.cssy.xxkj.logic.contants.DocumentSatusUitl;
import com.cssy.xxkj.logic.dao.LogicWarehouseInventoryDAO;
import com.cssy.xxkj.logic.entity.LogicAllocatInwhDO;
import com.cssy.xxkj.logic.entity.LogicAllocatInwhItemDO;
import com.cssy.xxkj.logic.entity.LogicAllocatOutwhDO;
import com.cssy.xxkj.logic.entity.LogicAllocatOutwhItemDO;
import com.cssy.xxkj.logic.entity.LogicAllocationDO;
import com.cssy.xxkj.logic.entity.LogicAllocationItemDO;
import com.cssy.xxkj.logic.entity.LogicCheckBackDO;
import com.cssy.xxkj.logic.entity.LogicCheckBackItemDO;
import com.cssy.xxkj.logic.entity.LogicMaterialBackDO;
import com.cssy.xxkj.logic.entity.LogicMaterialBackItemDO;
import com.cssy.xxkj.logic.entity.LogicOutsideBoundDO;
import com.cssy.xxkj.logic.entity.LogicOutsideBoundItemDO;
import com.cssy.xxkj.logic.entity.LogicOutsideStockDO;
import com.cssy.xxkj.logic.entity.LogicOutsideStockItemDO;
import com.cssy.xxkj.logic.entity.LogicProductionStorageinDO;
import com.cssy.xxkj.logic.entity.LogicProductionStorageinItemDO;
import com.cssy.xxkj.logic.entity.LogicProductionStorageoutDO;
import com.cssy.xxkj.logic.entity.LogicProductionStorageoutItemDO;
import com.cssy.xxkj.logic.entity.LogicPurchaseReturnDO;
import com.cssy.xxkj.logic.entity.LogicPurchaseReturnItemDO;
import com.cssy.xxkj.logic.entity.LogicPurchaseWareDO;
import com.cssy.xxkj.logic.entity.LogicPurchaseWareItemDO;
import com.cssy.xxkj.logic.entity.LogicWarehouseBatchInDO;
import com.cssy.xxkj.logic.entity.LogicWarehouseBatchInItemDO;
import com.cssy.xxkj.logic.entity.LogicWarehouseDetailsDO;
import com.cssy.xxkj.logic.entity.LogicWarehouseInventoryDO;
import com.cssy.xxkj.logic.entity.LogicWarehouseMaterialoutDO;
import com.cssy.xxkj.logic.entity.LogicWarehouseMaterialoutItemDO;
import com.cssy.xxkj.logic.entity.LogicWarehouseOtherinDO;
import com.cssy.xxkj.logic.entity.LogicWarehouseOtherinItemDO;
import com.cssy.xxkj.logic.entity.LogicWarehouseOtheroutDO;
import com.cssy.xxkj.logic.entity.LogicWarehouseOtheroutItemDO;
import com.cssy.xxkj.logic.entity.LogicWhCheckTaskDO;
import com.cssy.xxkj.logic.entity.LogicWhCheckTaskItemDO;
import com.cssy.xxkj.logic.service.ILogicHsUtilService;
import com.cssy.xxkj.logic.service.ILogicWarehouseDetailsService;
import com.cssy.xxkj.logic.service.ILogicWarehouseInventoryService;
import com.plat.exception.SyBaseException;
import com.plat.helper.SearchCondition;
import com.plat.helper.SearchConditions;
import com.plat.util.GlobalResLoader;

/**
 * 修改物料仓库库存公用类
 * @author zeyong.gui
 *
 */
@Service("logicHsUtilService")
public class LogicHsUtilServiceImpl implements ILogicHsUtilService{
	
	@Resource(name = "logicWarehouseDetailsService")
	private ILogicWarehouseDetailsService logicWarehouseDetailsService;
	
	@Resource(name = "logicWarehouseInventoryService")
	private ILogicWarehouseInventoryService logicWarehouseInventoryService;
	
	@Resource(name = "logicWarehouseInventoryDAO")
	private LogicWarehouseInventoryDAO logicWarehouseInventoryDAO;
	
	//仓库Service
	@Resource(name = "basicStorageInfoTypeTestService")
	private IBasicStorageInfoTypeTestService basicStorageInfoTypeTestService;
	
	//仓库管理Service
	@Resource(name = "basicStorageInfoTestService")
	private IBasicStorageInfoTestService basicStorageInfoTestService;

	//修改采购入库物料仓库库存，增加库存
	@Override
	public void processHsPurchaseWareItem(LogicPurchaseWareDO mainEntity,
			LogicPurchaseWareItemDO itemEntity, User user)
			throws SyBaseException{
		LogicWarehouseDetailsDO whs = new LogicWarehouseDetailsDO();
		whs.setZd001BillCode(mainEntity.getZd003Code()); 
		whs.setZd002BillType(BillTypeConstant.PURCHASEWARE);
		whs.setZd003WhId(mainEntity.getZd005WhId());
		whs.setZd003WhName(mainEntity.getZd007WhName());
		whs.setZd003WhCode(mainEntity.getZd006WhCode());
		whs.setZd004WhPositionId("");
		whs.setZd004WhPositionCode("");
		whs.setZd005MaterialsId(itemEntity.getZd003MaterId());
		whs.setZd005MaterialsCode(itemEntity.getZd004Code());
		whs.setZd005MaterialsName(itemEntity.getZd005Name());
		whs.setZd006MaterialsSpec(itemEntity.getZd011Size());
		whs.setZd007MaterialsModel(itemEntity.getZd007Model());
		whs.setZd008MaterialsColor(itemEntity.getZd009Color());
		whs.setZd008MaterialsQuanlity(itemEntity.getZd010Quality());
		whs.setZd009BasicUnit(itemEntity.getZd012Unit());
		whs.setZd011BasicQuantity(itemEntity.getZd018HsQuantity());
		whs.setZd012Status("");
		whs.setZd013Price(itemEntity.getZd016Price());//不含税
		whs.setZd014StockPrice(itemEntity.getZd017TaxPrice());//含税
		whs.setZd019Batch(mainEntity.getZd012Batch()==null?Constants.SYS_DEFAULT_BATCH:mainEntity.getZd012Batch());
		whs.setZd020PiCode(mainEntity.getZd016PiCode());
		whs.setZd022ConsumerCode(mainEntity.getZd008SupeCode());
		whs.setZd022ConsumerID(mainEntity.getZd008SupeId());
		whs.setZd022ConsumerName(mainEntity.getZd008SupeName());
		whs.setBizCreatorName(user.getName());
		whs.setBizCreatorDate(new Date());
		logicWarehouseInventoryService.updateWhAffstockQuantity(whs,user, true);
	}
	
	//修改采购退货物料仓库库存,減少庫存
	@Override
	public void processHsPurhcaseReturnItem(LogicPurchaseReturnDO mainEntity,
			LogicPurchaseReturnItemDO itemEntity, User user)
			throws SyBaseException {
		try{
			LogicWarehouseDetailsDO whs = new LogicWarehouseDetailsDO();
			whs.setZd001BillCode(mainEntity.getZd003Code());
			whs.setZd002BillType(BillTypeConstant.PURCHASERETURN);
			whs.setZd003WhId(mainEntity.getZd007WhId());
			whs.setZd003WhCode(mainEntity.getZd007WhCode());
			whs.setZd003WhName(mainEntity.getZd007WhName());
			whs.setZd004WhPositionId(itemEntity.getZd002HubId());
			whs.setZd004WhPositionCode(itemEntity.getZd002HubCode());
			whs.setZd005MaterialsId(itemEntity.getZd003MaterId());
			whs.setZd005MaterialsCode(itemEntity.getZd004MaterCode());
			whs.setZd005MaterialsName(itemEntity.getZd005MaterName());
			whs.setZd006MaterialsSpec(itemEntity.getZd012MaterSize());
			whs.setZd007MaterialsModel(itemEntity.getZd008MaterModel());
			whs.setZd008MaterialsColor(itemEntity.getZd010MaterColor());
			whs.setZd008MaterialsQuanlity(itemEntity.getZd011MaterQuality());
			whs.setZd009BasicUnit(itemEntity.getZd016Unit());
			whs.setZd011BasicQuantity(itemEntity.getZd020BackQuantity().negate());
			whs.setZd012Status("");
			whs.setZd013Price(itemEntity.getZd014Price());
			whs.setZd014StockPrice(itemEntity.getZd013TaxPrice());
			whs.setZd019Batch(Constants.SYS_DEFAULT_BATCH);
			whs.setZd020PiCode(mainEntity.getZd004PiCode());
			whs.setBizCreatorName(user.getName());
			whs.setBizCreatorDate(new Date());
			logicWarehouseInventoryService.updateWhAffstockQuantity(whs,user, false);
		}catch(Exception e){
			e.printStackTrace();
			throw new SyBaseException(GlobalResLoader.getOpfailed()+ e.getMessage());
		}
	}
	

	//修改调拨发起物料仓库库存，减少库存
	@Override
	public void processHsAllocatOutwhItem(LogicAllocatOutwhDO mainEntity,
			LogicAllocatOutwhItemDO itemEntity, User user)
			throws SyBaseException {
		try{
			//减少发起仓的库存
			LogicWarehouseDetailsDO whs = new LogicWarehouseDetailsDO();
			whs.setZd001BillCode(mainEntity.getZd001Code());
			whs.setZd002BillType(BillTypeConstant.ALLOCATOUTWH);
			whs.setZd003WhId(mainEntity.getZd003OutWhId());
			whs.setZd003WhCode(mainEntity.getZd003OutWhCode());
			whs.setZd003WhName(mainEntity.getZd003OutWhName());
			whs.setZd004WhPositionId(itemEntity.getZd016HubId());
			whs.setZd004WhPositionCode(itemEntity.getZd016HubCode());
			whs.setZd005MaterialsId(itemEntity.getZd002MaterId());
			whs.setZd005MaterialsCode(itemEntity.getZd003Code());
			whs.setZd005MaterialsName(itemEntity.getZd004Name());
			whs.setZd006MaterialsSpec(itemEntity.getZd006Spec());
			whs.setZd007MaterialsModel(itemEntity.getZd007Model());
			whs.setZd009BasicUnit(itemEntity.getZd012Unit());
			whs.setZd011BasicQuantity(itemEntity.getZd017Quantity().negate());
			whs.setZd012Status("");
			whs.setZd013Price(itemEntity.getZd014Price());
			whs.setZd014StockPrice(itemEntity.getZd015TaxPrice());
			whs.setZd019Batch(Constants.SYS_DEFAULT_BATCH);
			whs.setBizCreatorName(user.getName());
			whs.setBizCreatorDate(new Date());
			logicWarehouseInventoryService.updateWhAffstockQuantity(whs,user, false);
			
			//增加接收仓库的在途库存
			LogicWarehouseDetailsDO inWh = new LogicWarehouseDetailsDO();
			inWh.setZd001BillCode(mainEntity.getZd001Code());
			inWh.setZd002BillType(BillTypeConstant.ALLOCATOUTWH);
			inWh.setZd003WhId(mainEntity.getZd004InWhId());
			inWh.setZd003WhCode(mainEntity.getZd004InWhCode());
			inWh.setZd003WhName(mainEntity.getZd004InWhName());
			inWh.setZd004WhPositionId(itemEntity.getZd016HubId());
			inWh.setZd004WhPositionCode(itemEntity.getZd016HubCode());
			inWh.setZd005MaterialsId(itemEntity.getZd002MaterId());
			inWh.setZd005MaterialsCode(itemEntity.getZd003Code());
			inWh.setZd005MaterialsName(itemEntity.getZd004Name());
			inWh.setZd006MaterialsSpec(itemEntity.getZd006Spec());
			inWh.setZd007MaterialsModel(itemEntity.getZd007Model());
			inWh.setZd009BasicUnit(itemEntity.getZd012Unit());
			inWh.setZd011BasicQuantity(itemEntity.getZd017Quantity());
			inWh.setZd012Status(DocumentSatusUitl.FIVE+"");
			inWh.setZd013Price(itemEntity.getZd014Price());
			inWh.setZd014StockPrice(itemEntity.getZd015TaxPrice());
			inWh.setZd019Batch(Constants.SYS_DEFAULT_BATCH);
			inWh.setBizCreatorName(user.getName());
			inWh.setBizCreatorDate(new Date());
			logicWarehouseInventoryService.updateWhAffstockQuantity(inWh,user, false);
		}catch(Exception e){
			e.printStackTrace();
			throw new SyBaseException(GlobalResLoader.getOpfailed()+ e.getMessage());
		}
	}
	
	//修改调拨接收物料仓库库存，增加库存
	@Override
	public void processHsAllocatInwhItem(LogicAllocatInwhDO mainEntity,
			LogicAllocatInwhItemDO itemEntity, User user)
			throws SyBaseException {
		try{
			//增加接收仓库的库存
			LogicWarehouseDetailsDO whs = new LogicWarehouseDetailsDO();
			whs.setZd001BillCode(mainEntity.getZd002InCode());
			whs.setZd002BillType(BillTypeConstant.ALLOCATINWH);
			whs.setZd003WhId(mainEntity.getZd004InWhId());
			whs.setZd003WhCode(mainEntity.getZd004InWhCode());
			whs.setZd003WhName(mainEntity.getZd004InWhName());
			whs.setZd004WhPositionId(itemEntity.getZd016HubId());
			whs.setZd004WhPositionCode(itemEntity.getZd016HubCode());
			whs.setZd005MaterialsId(itemEntity.getZd002MaterId());
			whs.setZd005MaterialsCode(itemEntity.getZd003Code());
			whs.setZd005MaterialsName(itemEntity.getZd004Name());
			whs.setZd006MaterialsSpec(itemEntity.getZd006Spec());
			whs.setZd007MaterialsModel(itemEntity.getZd007Model());
			whs.setZd009BasicUnit(itemEntity.getZd012Unit());
			whs.setZd011BasicQuantity(itemEntity.getZd019InQuantity());
			whs.setZd012Status("");
			whs.setZd013Price(itemEntity.getZd014Price());
			whs.setZd014StockPrice(itemEntity.getZd015TaxPrice());
			whs.setZd019Batch(Constants.SYS_DEFAULT_BATCH);
			whs.setBizCreatorName(user.getName());
			whs.setBizCreatorDate(new Date());
			logicWarehouseInventoryService.updateWhAffstockQuantity(whs,user, false);
			//减少接收仓库的在途库存
			LogicWarehouseDetailsDO ztWh = new LogicWarehouseDetailsDO();
			ztWh.setZd001BillCode(mainEntity.getZd002InCode());
			ztWh.setZd002BillType(BillTypeConstant.ALLOCATINWH);
			ztWh.setZd003WhId(mainEntity.getZd004InWhId());
			ztWh.setZd003WhCode(mainEntity.getZd004InWhCode());
			ztWh.setZd003WhName(mainEntity.getZd004InWhName());
			ztWh.setZd004WhPositionId(itemEntity.getZd016HubId());
			ztWh.setZd004WhPositionCode(itemEntity.getZd016HubCode());
			ztWh.setZd005MaterialsId(itemEntity.getZd002MaterId());
			ztWh.setZd005MaterialsCode(itemEntity.getZd003Code());
			ztWh.setZd005MaterialsName(itemEntity.getZd004Name());
			ztWh.setZd006MaterialsSpec(itemEntity.getZd006Spec());
			ztWh.setZd007MaterialsModel(itemEntity.getZd007Model());
			ztWh.setZd009BasicUnit(itemEntity.getZd012Unit());
			ztWh.setZd011BasicQuantity(itemEntity.getZd019InQuantity().negate());
			ztWh.setZd012Status(DocumentSatusUitl.FIVE+"");
			whs.setZd013Price(itemEntity.getZd014Price());
			whs.setZd014StockPrice(itemEntity.getZd015TaxPrice());
			ztWh.setZd019Batch(Constants.SYS_DEFAULT_BATCH);
			ztWh.setBizCreatorName(user.getName());
			ztWh.setBizCreatorDate(new Date());
			logicWarehouseInventoryService.updateWhAffstockQuantity(ztWh,user, false);
		}catch(Exception e){
			e.printStackTrace();
			throw new SyBaseException(GlobalResLoader.getOpfailed()+ e.getMessage());
		}
	}
	
	//修改委外物料入库的仓库库存，增加库存
	@Override
	public void processHsOutSideInItem(LogicOutsideStockDO mainEntity,
			LogicOutsideStockItemDO itemEntity, User user)
			throws SyBaseException {
		try{
			LogicWarehouseDetailsDO whs = new LogicWarehouseDetailsDO();
			whs.setZd001BillCode(mainEntity.getZd001Code());
			whs.setZd002BillType(BillTypeConstant.OUTSIDEIN);
			whs.setZd003WhId(mainEntity.getZd003WhId());
			whs.setZd003WhCode(mainEntity.getZd003WhCode());
			whs.setZd003WhName(mainEntity.getZd003WhName());
			whs.setZd004WhPositionId(itemEntity.getZd017WhShipId());
			whs.setZd004WhPositionCode(itemEntity.getZd017WhShipCode());
			whs.setZd005MaterialsId(itemEntity.getZd003MaterId());
			whs.setZd005MaterialsCode(itemEntity.getZd004MaterCode());
			whs.setZd005MaterialsName(itemEntity.getZd005MaterName());
			whs.setZd006MaterialsSpec(itemEntity.getZd007MaterSpec());
			whs.setZd007MaterialsModel(itemEntity.getZd008MaterModel());
			whs.setZd009BasicUnit(itemEntity.getZd013Unit());
			whs.setZd011BasicQuantity(itemEntity.getZd018InQuantity());
			whs.setZd012Status("");
			whs.setZd013Price(itemEntity.getZd014Price());
			whs.setZd014StockPrice(itemEntity.getZd014TaxPrice());
			whs.setZd019Batch(Constants.SYS_DEFAULT_BATCH);
			whs.setBizCreatorName(user.getName());
			whs.setBizCreatorDate(new Date());
			logicWarehouseInventoryService.updateWhAffstockQuantity(whs,user, false);
		}catch(Exception e){
			e.printStackTrace();
			throw new SyBaseException(GlobalResLoader.getOpfailed()+ e.getMessage());
		}
	}
	
	//修改委外物料出库的仓库库存，增加库存
	@Override
	public void processHsOutSideOutItem(LogicOutsideBoundDO mainEntity, LogicOutsideBoundItemDO itemEntity, User user)
		throws SyBaseException{
		try{
			LogicWarehouseDetailsDO whs = new LogicWarehouseDetailsDO();
			whs.setZd001BillCode(mainEntity.getZd001Code());
			whs.setZd002BillType(BillTypeConstant.OUTSIDEOUT);
			whs.setZd003WhId(mainEntity.getZd003WhId());
			whs.setZd003WhCode(mainEntity.getZd003WhCode());
			whs.setZd003WhName(mainEntity.getZd003WhName());
			whs.setZd004WhPositionId(itemEntity.getZd017WhShipId());
			whs.setZd004WhPositionCode(itemEntity.getZd017WhShipCode());
			whs.setZd005MaterialsId(itemEntity.getZd003MaterId());
			whs.setZd005MaterialsCode(itemEntity.getZd004MaterCode());
			whs.setZd005MaterialsName(itemEntity.getZd005MaterName());
			whs.setZd006MaterialsSpec(itemEntity.getZd007MaterSpec());
			whs.setZd007MaterialsModel(itemEntity.getZd008MaterModel());
			whs.setZd009BasicUnit(itemEntity.getZd013Unit());
			whs.setZd011BasicQuantity(itemEntity.getZd018OutQuantity());
			whs.setZd012Status("");
			whs.setZd013Price(itemEntity.getZd014Price());
			whs.setZd014StockPrice(itemEntity.getZd014TaxPrice());
			whs.setZd019Batch(Constants.SYS_DEFAULT_BATCH);
			whs.setBizCreatorName(user.getName());
			whs.setBizCreatorDate(new Date());
			logicWarehouseInventoryService.updateWhAffstockQuantity(whs,user, false);
		}catch(Exception e){
			e.printStackTrace();
			throw new SyBaseException(GlobalResLoader.getOpfailed()+ e.getMessage());
		}
	}
	
	//修改调拨的物料的仓库库存
	@Override
	public void processHsAllocationItem(LogicAllocationDO mainEntity, LogicAllocationItemDO itemEntity, User user)
		throws SyBaseException{
		try{
			//减少发起仓库的库存
			LogicWarehouseDetailsDO whs = new LogicWarehouseDetailsDO();
			whs.setZd001BillCode(mainEntity.getZd001Code());
			whs.setZd002BillType(BillTypeConstant.ALLOCATION);
			whs.setZd003WhId(mainEntity.getZd003OutWhId());
			whs.setZd003WhCode(mainEntity.getZd003OutWhCode());
			whs.setZd003WhName(mainEntity.getZd003OutWhName());
			whs.setZd004WhPositionId(itemEntity.getZd016HubId());
			whs.setZd004WhPositionCode(itemEntity.getZd016HubCode());
			whs.setZd005MaterialsId(itemEntity.getZd002MaterId());
			whs.setZd005MaterialsCode(itemEntity.getZd003Code());
			whs.setZd005MaterialsName(itemEntity.getZd004Name());
			whs.setZd006MaterialsSpec(itemEntity.getZd006Spec());
			whs.setZd007MaterialsModel(itemEntity.getZd007Model());
			whs.setZd008MaterialsColor(itemEntity.getZd009Color());
			whs.setZd008MaterialsQuanlity(itemEntity.getZd010Quality());
			whs.setZd009BasicUnit(itemEntity.getZd012Unit());
			whs.setZd011BasicQuantity(itemEntity.getZd019Quantity().negate());
			whs.setZd012Status("");
			whs.setZd013Price(itemEntity.getZd014Price());
			whs.setZd014StockPrice(itemEntity.getZd015TaxPrice());
			whs.setZd019Batch(Constants.SYS_DEFAULT_BATCH);
			whs.setZd020PiCode(itemEntity.getZd021PiCode());
			whs.setBizCreatorName(user.getName());
			whs.setBizCreatorDate(new Date());
			logicWarehouseInventoryService.updateWhAffstockQuantity(whs,user, false);
			//增加接收仓库的库存
			LogicWarehouseDetailsDO inWh = new LogicWarehouseDetailsDO();
			inWh.setZd001BillCode(mainEntity.getZd001Code());
			inWh.setZd002BillType(BillTypeConstant.ALLOCATION);
			inWh.setZd003WhId(mainEntity.getZd004InWhId());
			inWh.setZd003WhCode(mainEntity.getZd004InWhCode());
			inWh.setZd003WhName(mainEntity.getZd004InWhName());
			inWh.setZd004WhPositionId(itemEntity.getZd016HubId());
			inWh.setZd004WhPositionCode(itemEntity.getZd016HubCode());
			inWh.setZd005MaterialsId(itemEntity.getZd002MaterId());
			inWh.setZd005MaterialsCode(itemEntity.getZd003Code());
			inWh.setZd005MaterialsName(itemEntity.getZd004Name());
			inWh.setZd006MaterialsSpec(itemEntity.getZd006Spec());
			inWh.setZd007MaterialsModel(itemEntity.getZd007Model());
			inWh.setZd008MaterialsColor(itemEntity.getZd009Color());
			inWh.setZd008MaterialsQuanlity(itemEntity.getZd010Quality());
			inWh.setZd009BasicUnit(itemEntity.getZd012Unit());
			inWh.setZd011BasicQuantity(itemEntity.getZd019Quantity());
			inWh.setZd012Status("");
			inWh.setZd013Price(itemEntity.getZd014Price());
			inWh.setZd014StockPrice(itemEntity.getZd015TaxPrice());
			inWh.setZd019Batch(Constants.SYS_DEFAULT_BATCH);
			inWh.setZd020PiCode(itemEntity.getZd021PiCode());
			inWh.setBizCreatorName(user.getName());
			inWh.setBizCreatorDate(new Date());
			logicWarehouseInventoryService.updateWhAffstockQuantity(inWh,user, false);
			
		}catch(Exception e){
			e.printStackTrace();
			throw new SyBaseException(GlobalResLoader.getOpfailed()+ e.getMessage());
		}
	}
	
	//修改成品入库的仓库库存
	@Override
	public void processProdStorageInItem(LogicProductionStorageinDO mainEntity, LogicProductionStorageinItemDO itemEntity, User user)
		throws SyBaseException{
		try{
			//增加仓库的库存
			LogicWarehouseDetailsDO lw = new LogicWarehouseDetailsDO();
			lw.setZd001BillCode(mainEntity.getZd001InCode());
			lw.setZd002BillType(BillTypeConstant.PROIN);
			lw.setZd003WhId(mainEntity.getZd004Whid());
			lw.setZd003WhCode(mainEntity.getZd004WhCode());
			lw.setZd003WhName(mainEntity.getZd004WhName());
			lw.setZd004WhPositionId(itemEntity.getZd011WhLocationId());
			lw.setZd004WhPositionCode(itemEntity.getZd012WhLocationCode());
			lw.setZd005MaterialsId(itemEntity.getZd002MaterialsId());
			lw.setZd005MaterialsCode(itemEntity.getZd002MaterialsCode());//编码
			lw.setZd005MaterialsName(itemEntity.getZd002MaterialsName());//名称
			lw.setZd006MaterialsSpec(itemEntity.getZd015MaterialsSize());//尺寸，大小
			lw.setZd007MaterialsModel(itemEntity.getZd004MaterialsModel());//型号
			lw.setZd008MaterialsQuanlity(itemEntity.getZd017MaterialsQuality());//材质
			lw.setZd008MaterialsColor(itemEntity.getZd016MaterialsColor());//颜色/做法
			lw.setZd009BasicUnit(itemEntity.getZd006Unit());
			lw.setZd011BasicQuantity(itemEntity.getZd007Quantity());
			lw.setZd012Status(itemEntity.getZd008Status());
			lw.setZd013Price(itemEntity.getZd009Price());
			lw.setZd014StockPrice(null);
			lw.setZd019Batch(Constants.SYS_DEFAULT_BATCH);
			lw.setZd020PiCode(mainEntity.getZd003PiCode());//pi编号
			lw.setZd022ConsumerID(mainEntity.getZd012CustomerId());
			lw.setZd022ConsumerCode(mainEntity.getZd012CustomerCode());
			lw.setZd022ConsumerName(mainEntity.getZd012CustomerName());
			lw.setBizCreatorName(user.getName());
			lw.setBizCreatorDate(new Date());
			
			logicWarehouseInventoryService.updateWhAffstockQuantity(lw,user, false);
			
		}catch(Exception e){
			e.printStackTrace();
			throw new SyBaseException(GlobalResLoader.getOpfailed()+ e.getMessage());
		}
	}

	//修改成品出库的仓库库存
	@Override
	public void processProdStorageOutItem(LogicProductionStorageoutDO mainEntity, LogicProductionStorageoutItemDO itemEntity, User user)
		throws SyBaseException{
		try{
			//减少仓库的库存
			LogicWarehouseDetailsDO lw = new LogicWarehouseDetailsDO();
			lw.setZd001BillCode(mainEntity.getZd001OutCode());
			lw.setZd002BillType(BillTypeConstant.PROOUT);
			lw.setZd003WhId(mainEntity.getZd004WhId());
			lw.setZd003WhCode(mainEntity.getZd004WhCode());
			lw.setZd003WhName(mainEntity.getZd004WhName());
			lw.setZd004WhPositionId(itemEntity.getZd011WhLocationId());
			lw.setZd004WhPositionCode(itemEntity.getZd012WhLocationCode());
			lw.setZd005MaterialsId(itemEntity.getZd002MaterialsId());
			lw.setZd005MaterialsCode(itemEntity.getZd002MaterialsCode());
			lw.setZd005MaterialsName(itemEntity.getZd002MaterialsName());
			lw.setZd006MaterialsSpec(itemEntity.getZd016MaterialsSize());
			lw.setZd007MaterialsModel(itemEntity.getZd004MaterialsModel());
			lw.setZd008MaterialsQuanlity(itemEntity.getZd018MaterialsQuality());
			lw.setZd008MaterialsColor(itemEntity.getZd017MaterialsColor());
			lw.setZd009BasicUnit(itemEntity.getZd006Unit());
			lw.setZd011BasicQuantity(itemEntity.getZd007Quantity().negate());
			lw.setZd012Status(itemEntity.getZd008Status());
			lw.setZd013Price(itemEntity.getZd009Price());
			lw.setZd014StockPrice(null);
			lw.setZd019Batch(Constants.SYS_DEFAULT_BATCH);
			lw.setZd020PiCode(itemEntity.getZd024Picode());
			lw.setZd022ConsumerID(mainEntity.getZd012CustomerId());
			lw.setZd022ConsumerCode(mainEntity.getZd012CustomerCode());
			lw.setZd022ConsumerName(mainEntity.getZd012CustomerName());
			lw.setBizCreatorName(user.getName());
			lw.setBizCreatorDate(new Date());
			
			logicWarehouseInventoryService.updateWhAffstockQuantity(lw, user,false);
			
		}catch(Exception e){
			e.printStackTrace();
			throw new SyBaseException(GlobalResLoader.getOpfailed()+ e.getMessage());
		}
	}
	
	//修改领料出库的仓库库存
	public void processMaterailsOutItem(LogicWarehouseMaterialoutDO mainEntity, LogicWarehouseMaterialoutItemDO itemEntity, User user)
		throws SyBaseException{
		try{
			//减少库存
			LogicWarehouseDetailsDO lw = new LogicWarehouseDetailsDO();
			lw.setZd001BillCode(mainEntity.getZd001MaterialCode());
			lw.setZd002BillType(BillTypeConstant.MATERIALOUT);//生产领料
			lw.setZd003WhId(mainEntity.getZd011WhId());
			lw.setZd003WhName(mainEntity.getZd011WhName());
			lw.setZd003WhCode(mainEntity.getZd011WhCode());
			lw.setZd004WhPositionId(itemEntity.getZd011WhLocationId());
			lw.setZd004WhPositionCode(itemEntity.getZd012WhLocationCode());
			lw.setZd005MaterialsId(itemEntity.getZd002MaterialsId());
			lw.setZd005MaterialsCode(itemEntity.getZd002MaterialsCode());
			lw.setZd005MaterialsName(itemEntity.getZd002MaterialsName());
			lw.setZd006MaterialsSpec(itemEntity.getZd017MaterialsSize());
			lw.setZd007MaterialsModel(itemEntity.getZd004MaterialsModel());
			lw.setZd008MaterialsColor(itemEntity.getZd016MaterialsColor());
			lw.setZd008MaterialsQuanlity(itemEntity.getZd018MaterialsQuanlity());
			lw.setZd012Status(itemEntity.getZd008Status());
			lw.setZd009BasicUnit(itemEntity.getZd006Unit());
			lw.setZd011BasicQuantity(itemEntity.getZd007Quantity().negate());
			lw.setZd019Batch(Constants.SYS_DEFAULT_BATCH);
			lw.setZd020PiCode(itemEntity.getZd021PiCode());
			lw.setBizCreatorName(user.getName());
			lw.setBizCreatorDate(new Date());
			
			logicWarehouseInventoryService.updateWhAffstockQuantity(lw, user, false);
			
		}catch(Exception e){
			e.printStackTrace();
			throw new SyBaseException(GlobalResLoader.getOpfailed()+ e.getMessage());
		}
	}
	
	//修改其他入库的仓库库存
	@Override
	public void processHsOtherInItem(LogicWarehouseOtherinDO mainEntity, LogicWarehouseOtherinItemDO itemEntity, User user)
		throws SyBaseException{
		Map<String, Boolean> isStorage=getStorageType();
		try{
			//增加仓库的库存
			LogicWarehouseDetailsDO lw = new LogicWarehouseDetailsDO();
			lw.setZd001BillCode(mainEntity.getZd001InCode());
			lw.setZd002BillType(BillTypeConstant.OTHERINWH);
			lw.setZd003WhId(mainEntity.getZd004Whid());
			lw.setZd003WhCode(mainEntity.getZd004WhCode());
			lw.setZd003WhName(mainEntity.getZd004WhName());
			lw.setZd004WhPositionId(itemEntity.getZd011WhLocationId());
			lw.setZd004WhPositionCode(itemEntity.getZd012WhLocationCode());
			lw.setZd005MaterialsId(itemEntity.getZd002MaterialsId());
			lw.setZd005MaterialsCode(itemEntity.getZd002MaterialsCode());
			lw.setZd005MaterialsName(itemEntity.getZd002MaterialsName());
			lw.setZd006MaterialsSpec(itemEntity.getZd005MaterialsSize());
			lw.setZd007MaterialsModel(itemEntity.getZd004MaterialsModel());
			lw.setZd008MaterialsQuanlity(itemEntity.getZd005MaterialsQuanlity());
			lw.setZd008MaterialsColor(itemEntity.getZd005MaterialsColor());
			lw.setZd009BasicUnit(itemEntity.getZd006Unit());
			lw.setZd011BasicQuantity(itemEntity.getZd007Quantity());
			lw.setZd012Status(itemEntity.getZd008Status());
			lw.setZd013Price(itemEntity.getZd009Price());
			lw.setZd014StockPrice(null);
			lw.setZd019Batch(Constants.SYS_DEFAULT_BATCH);
			lw.setZd020PiCode(mainEntity.getZd005PiCode());
			if(isStorage.get(mainEntity.getZd004Whid())){
				//是成品取客户的值 
				lw.setZd022ConsumerID(mainEntity.getZd013AccountID());
				lw.setZd022ConsumerCode(mainEntity.getZd013AccountCode());
				lw.setZd022ConsumerName(mainEntity.getZd013AccountName());
			}else{
				//材料仓 取供应商
				lw.setZd022ConsumerID(mainEntity.getZd011CustomerID());
				lw.setZd022ConsumerCode(mainEntity.getZd011CustomerCode());
				lw.setZd022ConsumerName(mainEntity.getZd011CustomerName());
			}
			lw.setBizCreatorName(user.getName());
			lw.setBizCreatorDate(new Date());
			
			logicWarehouseInventoryService.updateWhAffstockQuantity(lw, user,true);
			
		}catch(Exception e){
			e.printStackTrace();
			throw new SyBaseException(GlobalResLoader.getOpfailed()+ e.getMessage());
		}
	}
	
	//修改其他出库的仓库库存
	@Override
	public void processHsOtherOutItem(LogicWarehouseOtheroutDO mainEntity, 
			LogicWarehouseOtheroutItemDO itemEntity, User user)throws SyBaseException{
		Map<String, Boolean> isStorage=getStorageType();
		LogicWarehouseDetailsDO lw = new LogicWarehouseDetailsDO();
		lw.setZd001BillCode(mainEntity.getZd001OutCode());
		lw.setZd002BillType(BillTypeConstant.OTHEROUTWH);
		lw.setZd005MaterialsId(itemEntity.getZd002MaterialsId());
		lw.setZd005MaterialsCode(itemEntity.getZd002MaterialsCode());
		lw.setZd005MaterialsName(itemEntity.getZd002MaterialsName());
		lw.setZd006MaterialsSpec(itemEntity.getZd003MaterialsSpec());
		lw.setZd007MaterialsModel(itemEntity.getZd004MaterialsModel());
		lw.setZd008MaterialsQuanlity(itemEntity.getZd017MaterialsQuanlity());
		lw.setZd008MaterialsColor(itemEntity.getZd016MaterialsColor());
		lw.setZd012Status(itemEntity.getZd008Status());
		lw.setZd004WhPositionId(itemEntity.getZd011WhLocationId());
		lw.setZd004WhPositionCode(itemEntity.getZd012WhLocationCode());
		lw.setZd003WhId(mainEntity.getZd004Whid());
		lw.setZd003WhName(mainEntity.getZd004WhName());
		lw.setZd003WhCode(mainEntity.getZd004WhCode());
		lw.setZd009BasicUnit(itemEntity.getZd006Unit());
		lw.setZd011BasicQuantity(itemEntity.getZd007Quantity().negate());
		lw.setZd013Price(itemEntity.getZd009Price());//不含税
		lw.setZd019Batch(Constants.SYS_DEFAULT_BATCH);
		lw.setZd020PiCode(itemEntity.getZd018PiCode());
		if(isStorage.get(mainEntity.getZd004Whid())){
			//是成品取客户的值 
			lw.setZd022ConsumerID(mainEntity.getZd011CustomerID());
			lw.setZd022ConsumerCode(mainEntity.getZd011CustomerCode());
			lw.setZd022ConsumerName(mainEntity.getZd011CustomerName());
		}
		lw.setBizCreatorName(user.getName());
		lw.setBizCreatorDate(new Date());
		
		logicWarehouseInventoryService.updateWhAffstockQuantity(lw, user,false);
	}
	
	//反审其他出入库改变库存
	@Override
	public void processCheckBack(LogicCheckBackDO mainEntity,
			LogicCheckBackItemDO itemEntity , User user) throws SyBaseException {
		try {
			LogicWarehouseDetailsDO lw = new LogicWarehouseDetailsDO();
			lw.setZd001BillCode(mainEntity.getZd001CheckCode());
			lw.setZd002BillType(BillTypeConstant.CHECKBACK);
			lw.setZd003WhId(mainEntity.getZd004Whid());
			lw.setZd003WhCode(mainEntity.getZd004WhCode());
			lw.setZd003WhName(mainEntity.getZd004WhName());
			lw.setZd004WhPositionId(itemEntity.getZd011WhLocationId());
			lw.setZd004WhPositionCode(itemEntity.getZd012WhLocationCode());
			lw.setZd005MaterialsId(itemEntity.getZd002MaterialsId());
			lw.setZd005MaterialsCode(itemEntity.getZd003MaterialsCode());
			lw.setZd005MaterialsName(itemEntity.getZd004MaterialsName());
			lw.setZd006MaterialsSpec(itemEntity.getZd005MaterialsSpec());
			lw.setZd007MaterialsModel(itemEntity.getZd006MaterialsModel());
			lw.setZd008MaterialsQuanlity(itemEntity.getZd018MaterialsQuality());
			lw.setZd008MaterialsColor(itemEntity.getZd017MaterialsColor());
			lw.setZd009BasicUnit(itemEntity.getZd008Unit());
			lw.setZd011BasicQuantity(itemEntity.getZd023BackQuanlity());//增加不取负数
			lw.setZd012Status(itemEntity.getZd008Status());
			lw.setZd013Price(itemEntity.getZd009Price());
			lw.setZd014StockPrice(null);
			lw.setZd019Batch(Constants.SYS_DEFAULT_BATCH);
			lw.setZd020PiCode(itemEntity.getZd025PiCode());
			lw.setBizCreatorName(user.getName());
			lw.setBizCreatorDate(new Date());
			logicWarehouseInventoryService.updateWhAffstockQuantity(lw,user, false);
		} catch (Exception e) {
			e.printStackTrace();
			throw new SyBaseException(GlobalResLoader.getOpfailed()+ e.getMessage());
		}
		
	}

	@Override
	public void processCheckTask(LogicWhCheckTaskDO mainEntity,
			LogicWhCheckTaskItemDO itemEntity, User user)
			throws SyBaseException {
		try {
			LogicWarehouseDetailsDO lw = new LogicWarehouseDetailsDO();
			lw.setZd001BillCode(mainEntity.getZd002TaskCode());
			lw.setZd002BillType(BillTypeConstant.CHECKTASK);
			lw.setZd003WhId(mainEntity.getZd001WhId());
			lw.setZd003WhCode(mainEntity.getZd001WhCode());
			lw.setZd003WhName(mainEntity.getZd001WhName());
			lw.setZd004WhPositionId(null);//仓位
			lw.setZd004WhPositionCode(null);
			lw.setZd005MaterialsId(itemEntity.getZd002MaterId());
			lw.setZd005MaterialsCode(itemEntity.getZd002MaterCode());
			lw.setZd005MaterialsName(itemEntity.getZd002MaterName());
			lw.setZd006MaterialsSpec(itemEntity.getZd002MaterSpec());
			lw.setZd007MaterialsModel(itemEntity.getZd002MaterModel());
			lw.setZd008MaterialsQuanlity(itemEntity.getZd002MaterQuality());
			lw.setZd008MaterialsColor(itemEntity.getZd002MaterColor());
			lw.setZd009BasicUnit(itemEntity.getZd003Unit());
			lw.setZd011BasicQuantity(itemEntity.getZd006HsCyQuantity());
			lw.setZd012Status(null);
			lw.setZd013Price(null);
			lw.setZd014StockPrice(null);
			lw.setZd019Batch(Constants.SYS_DEFAULT_BATCH);
			lw.setZd020PiCode(itemEntity.getZd011PiCode());
			lw.setBizCreatorName(user.getName());
			lw.setBizCreatorDate(new Date());
			logicWarehouseInventoryService.updateWhAffstockQuantity(lw,user, false);
		} catch (Exception e) {
			e.printStackTrace();
			throw new SyBaseException(GlobalResLoader.getOpfailed()+ e.getMessage());
		}
		
	}
	
	//处理库存数据
	public void processWareHouseTask(SearchConditions scs)throws SyBaseException{
		try{
			//查询入库的
			SearchConditions whTailScs = new SearchConditions();
			whTailScs.addCondition("zd002BillType", "CK", SearchCondition.OP_EQUAL);
			Map<String, LogicWarehouseDetailsDO> whTailInMap = this.getQueryTailToMap(whTailScs);
			
			//查询出库的单据
			whTailScs.clearCondition();
			whTailScs.addCondition("zd002BillType", "CO", SearchCondition.OP_EQUAL);
			Map<String, LogicWarehouseDetailsDO> whTailOutMap = this.getQueryTailToMap(whTailScs);
			
			//查询现有库存列表
			whTailScs.clearCondition();
			Map<String, LogicWarehouseInventoryDO> whInMap = this.getQueryInToMap(whTailScs);
			for(String keyStr : whTailOutMap.keySet()){
				if(StringUtils.isBlank(keyStr)){
					continue;
				}
				LogicWarehouseDetailsDO outTail = whTailOutMap.get(keyStr);
				LogicWarehouseDetailsDO inTail = whTailInMap.get(keyStr);
				if(inTail==null){
					throw new SyBaseException("没有找到唯一标识的："+keyStr+"的入库信息记录");
				}else{
					//出库数量
					BigDecimal outQuantity = outTail.getZd011BasicQuantity();
					//入库数量
					BigDecimal inQuantity = inTail.getZd011BasicQuantity();
					//比较
					BigDecimal _outQuantity = outQuantity.negate();
					int comQ = _outQuantity.compareTo(inQuantity);
					LogicWarehouseInventoryDO whIn = whInMap.get(keyStr);
					if(whIn==null){
						throw new SyBaseException("没有找到该出库标识："+keyStr+"库存信息");
					}
					if(comQ==0||comQ==-1){
						//表示出库数量等于或者等于入库数量
						BigDecimal subQuantity = BigDecimal.ZERO;
						BigDecimal kcQuantity = whIn.getZd009Quantity()==null?BigDecimal.ZERO:whIn.getZd009Quantity();
						subQuantity = kcQuantity.add(outQuantity);
						whIn.setZd009Quantity(subQuantity);
						whIn.setBizModifyName("admin");
						whIn.setBizModifyDate(new Date());
						logicWarehouseInventoryDAO.updateLogicWarehouseInventoryDO(whIn);//更新库存
					}else{
						//表示出库数量大于入库输入，则需要减少原有的库存数量
						whIn.setZd009Quantity(inQuantity.negate());
						whIn.setBizModifyName("admin");
						whIn.setBizModifyDate(new Date());
						logicWarehouseInventoryDAO.updateLogicWarehouseInventoryDO(whIn);//更新库存
						
						//剩余要出库的数量
						BigDecimal welQuantity =  _outQuantity.subtract(inQuantity);
						
						String keyStr1 = outTail.getZd003WhId()+"_库存_"+outTail.getZd005MaterialsId()
							+outTail.getZd006MaterialsSpec()+"_"+outTail.getZd007MaterialsModel()+"_"+outTail.getZd008MaterialsColor()+"_"
							+outTail.getZd008MaterialsQuanlity();
						String keyStr2 = outTail.getZd003WhId()+"_备货__"+outTail.getZd005MaterialsId()
							+outTail.getZd006MaterialsSpec()+"_"+outTail.getZd007MaterialsModel()+"_"+outTail.getZd008MaterialsColor()+"_"
							+outTail.getZd008MaterialsQuanlity();
						LogicWarehouseInventoryDO kcwhIn = whInMap.get(keyStr1);
						if(kcwhIn==null){
							LogicWarehouseInventoryDO _kcwhIn = whInMap.get(keyStr2);
							if(_kcwhIn==null){
								throw new SyBaseException("库存没有");
							}else{
								
								BigDecimal bhQuantity = _kcwhIn.getZd009Quantity()==null?BigDecimal.ZERO:_kcwhIn.getZd009Quantity();
								int compZero = BigDecimal.ZERO.compareTo(bhQuantity.subtract(welQuantity));
								if(compZero==-1){
									throw new SyBaseException("备货的数量少于已出库的数量");
								}
								//出货备货数量的值
								BigDecimal chfQuantity = bhQuantity.subtract(welQuantity);
								_kcwhIn.setZd009Quantity(chfQuantity.negate());
								_kcwhIn.setBizModifyName("admin");
								_kcwhIn.setBizModifyDate(new Date());
								logicWarehouseInventoryDAO.updateLogicWarehouseInventoryDO(_kcwhIn);//更新库存
							}
						}else{
							//pi编号为库存的库存值
							BigDecimal pikcQuantity = kcwhIn.getZd009Quantity()==null?BigDecimal.ZERO:kcwhIn.getZd009Quantity();
							int pikcCp = pikcQuantity.subtract(welQuantity).compareTo(BigDecimal.ZERO);
							if(pikcCp==1||pikcCp==0){
								kcwhIn.setZd009Quantity(pikcQuantity.subtract(welQuantity).negate());
								kcwhIn.setBizModifyName("admin");
								kcwhIn.setBizModifyDate(new Date());
								logicWarehouseInventoryDAO.updateLogicWarehouseInventoryDO(kcwhIn);
							}else{
								kcwhIn.setZd009Quantity(pikcQuantity.negate());
								kcwhIn.setBizModifyName("admin");
								kcwhIn.setBizModifyDate(new Date());
								logicWarehouseInventoryDAO.updateLogicWarehouseInventoryDO(kcwhIn);
								
								LogicWarehouseInventoryDO beihwhIn = whInMap.get(keyStr2);
								if(beihwhIn==null){
									throw new SyBaseException("没有备货的数量");
								}
								//剩余要出库的数量
								BigDecimal bhOutQuantity = welQuantity.subtract(pikcQuantity);
								BigDecimal beihQuantity = beihwhIn.getZd009Quantity()==null?BigDecimal.ZERO:beihwhIn.getZd009Quantity();
								if(beihQuantity.compareTo(bhOutQuantity)==-1){
									throw new SyBaseException("");
								}
								beihwhIn.setZd009Quantity(beihQuantity.subtract(bhOutQuantity).negate());
								beihwhIn.setBizModifyName("admin");
								beihwhIn.setBizModifyDate(new Date());
								logicWarehouseInventoryDAO.updateLogicWarehouseInventoryDO(beihwhIn);
							}
						}
						
					}
				}
			}
		}catch(Exception e){
			e.printStackTrace();
			throw new SyBaseException(GlobalResLoader.getOpfailed()+ e.getMessage());
		}
	}
	
	@SuppressWarnings("unchecked")
	private Map<String, LogicWarehouseDetailsDO> getQueryTailToMap(SearchConditions scs){
		List<LogicWarehouseDetailsDO> tailList = logicWarehouseDetailsService.findListByExample(scs).getResults();
		if(tailList==null||tailList.size()==0||tailList.isEmpty()){
			return new HashMap<String, LogicWarehouseDetailsDO>();
		}else{
			
			Map<String, LogicWarehouseDetailsDO> whTailMap = new HashMap<String, LogicWarehouseDetailsDO>();
			for(LogicWarehouseDetailsDO whTail : tailList){
				if(whTail==null||StringUtils.isBlank(whTail.getId())){
					continue;
				}
				String keyStr = whTail.getZd003WhId()+"_"+whTail.getZd020PiCode()+"_"+whTail.getZd005MaterialsId()
						+whTail.getZd006MaterialsSpec()+"_"+whTail.getZd007MaterialsModel()+"_"+whTail.getZd008MaterialsColor()+"_"
						+whTail.getZd008MaterialsQuanlity();
				LogicWarehouseDetailsDO _whTail = whTailMap.get(keyStr);
				if(_whTail==null){
					whTailMap.put(keyStr, _whTail);
				}else{
					System.out.println(whTail.getId());
				}
			}
			return whTailMap;
		}
	}
	
	@SuppressWarnings("unchecked")
	private Map<String, LogicWarehouseInventoryDO> getQueryInToMap(SearchConditions scs){
		List<LogicWarehouseInventoryDO> whInList = logicWarehouseInventoryService.findListByExample(scs).getResults();
		if(whInList==null||whInList.isEmpty()||whInList.size()==0){
			return new HashMap<String, LogicWarehouseInventoryDO>();
		}else{
			Map<String, LogicWarehouseInventoryDO> whInMap = new HashMap<String, LogicWarehouseInventoryDO>();
			for(LogicWarehouseInventoryDO whIn : whInList){
				if(whIn==null||StringUtils.isBlank(whIn.getId())){
					continue;
				}
				String keyStr = whIn.getZd001WhId()+"_"+whIn.getZd026PiCode()+"_"+whIn.getZd003MaterialsId()+"_"
						+whIn.getZd006MaterialsSpec()+"_"+whIn.getZd007MaterialsModel()+"_"+whIn.getZd008MaterialsColor()+"_"
						+whIn.getZd009Quantity();
				whInMap.put(keyStr, whIn);
			}
			return whInMap;
		}
	}
	
	public void aginInStore()throws SyBaseException{
		try{
			//查询生生产入库的记录
			SearchConditions inScs = new SearchConditions();
			inScs.addCondition("zd002BillType", "PI", SearchCondition.OP_EQUAL);
			List<LogicWarehouseDetailsDO> prodTailList=logicWarehouseDetailsService.findListByExample(inScs).getResults();
			for(LogicWarehouseDetailsDO prodTail : prodTailList){
				if(prodTail==null||StringUtils.isBlank(prodTail.getId())){
					continue;
				}
				String userName = prodTail.getBizCreatorName();
				UserService us = new UserServiceImpl();
				com.byd.acegiext.domain.User user= us.getUserByName(userName, "1");
				logicWarehouseInventoryService.updateWhAffstockQuantity(prodTail,user, false);
			}
			//查询采购入库
			inScs.clearCondition();
			inScs.addCondition("zd002BillType", "PSW", SearchCondition.OP_EQUAL);
			List<LogicWarehouseDetailsDO> pcswTailList=logicWarehouseDetailsService.findListByExample(inScs).getResults();
			for(LogicWarehouseDetailsDO pcswTail : pcswTailList){
				if(pcswTail==null||StringUtils.isBlank(pcswTail.getId())){
					continue;
				}
				String userName = pcswTail.getBizCreatorName();
				UserService us = new UserServiceImpl();
				com.byd.acegiext.domain.User user= us.getUserByName(userName, "1");
				logicWarehouseInventoryService.updateWhAffstockQuantity(pcswTail,user, true);
			}
			//查询其他入库
			inScs.clearCondition();
			inScs.addCondition("zd002BillType", "CK", SearchCondition.OP_EQUAL);
			List<LogicWarehouseDetailsDO> qtTailList=logicWarehouseDetailsService.findListByExample(inScs).getResults();
			for(LogicWarehouseDetailsDO qtTail : qtTailList){
				if(qtTail==null||StringUtils.isBlank(qtTail.getId())){
					continue;
				}
				String userName = qtTail.getBizCreatorName();
				UserService us = new UserServiceImpl();
				com.byd.acegiext.domain.User user= us.getUserByName(userName, "1");
				logicWarehouseInventoryService.updateWhAffstockQuantity(qtTail,user, true);
			}
		}catch(Exception e){
			e.printStackTrace();
			throw new SyBaseException(GlobalResLoader.getOpfailed()+ e.getMessage());
		}
	}
	private Map<String, Boolean> getStorageType(){
		SearchConditions scsclean=new SearchConditions();
		//仓库类型
		List<BasicStorageInfoTypeTestDO> storageTypeList=basicStorageInfoTypeTestService.findListByExample(scsclean).getResults();
		Map<String, String> storageTypeMap=new HashMap<String, String>();
		for(BasicStorageInfoTypeTestDO bd:storageTypeList){
			storageTypeMap.put(bd.getId(), bd.getZd001Code());//为成品时  value=成品
		}
		//获得仓库的map
		Map<String , Boolean> isProSto= new HashMap<String, Boolean>();
		List<BasicStorageInfoTestDO> whList=basicStorageInfoTestService.findListByExample(scsclean).getResults();
		for(BasicStorageInfoTestDO wh:whList){
			String stm=storageTypeMap.get(wh.getZd001WhTypeId());
			if(StringUtils.isNotEmpty(stm)&&stm.equals("WHLX1411170001")){
				isProSto.put(wh.getId(), true);
			}else{
				isProSto.put(wh.getId(), false);
			}
		}
		return isProSto;
	}
	
	//退货
	public void processHsMaterialBackItem(LogicMaterialBackDO mainEntity, LogicMaterialBackItemDO itemEntity, User user)throws SyBaseException{
		try{
			//增加仓库的库存
			LogicWarehouseDetailsDO lw = new LogicWarehouseDetailsDO();
			lw.setZd001BillCode(mainEntity.getZd001Code());
			lw.setZd002BillType(BillTypeConstant.MATERBACK);
			lw.setZd003WhId(mainEntity.getZd006WhId());
			lw.setZd003WhCode(mainEntity.getZd006WhCode());
			lw.setZd003WhName(mainEntity.getZd006WhName());
			lw.setZd004WhPositionId(null);
			lw.setZd004WhPositionCode(null);
			lw.setZd005MaterialsId(itemEntity.getZd002MaterId());
			lw.setZd005MaterialsCode(itemEntity.getZd002MaterCode());
			lw.setZd005MaterialsName(itemEntity.getZd002MaterName());
			lw.setZd006MaterialsSpec(itemEntity.getZd002MaterSpec());
			lw.setZd007MaterialsModel(itemEntity.getZd002MaterModel());
			lw.setZd008MaterialsQuanlity(itemEntity.getZd002MaterQuanlity());
			lw.setZd008MaterialsColor(itemEntity.getZd002MaterColor());
			lw.setZd009BasicUnit(itemEntity.getZd003MaterUnit());
			lw.setZd011BasicQuantity(itemEntity.getZd010TheBackQuantity());
			lw.setZd012Status(null);
			lw.setZd013Price(itemEntity.getZd004MaterPrice());
			lw.setZd014StockPrice(null);
			lw.setZd019Batch(Constants.SYS_DEFAULT_BATCH);
			lw.setZd020PiCode(itemEntity.getZd012PiCode());
			lw.setZd022ConsumerID(mainEntity.getZd008CompId());
			lw.setZd022ConsumerCode(mainEntity.getZd008CompCode());
			lw.setZd022ConsumerName(mainEntity.getZd008CompName());
			lw.setBizCreatorName(user.getName());
			lw.setBizCreatorDate(new Date());
			
			logicWarehouseInventoryService.updateWhAffstockQuantity(lw, user,false);//需要跟新品均价
		}catch(Exception e){
			e.printStackTrace();
			throw new SyBaseException(GlobalResLoader.getOpfailed()+ e.getMessage());
		}
	}
	/**
	 * 多PI录入
	 */
	@Override
	public void processHsBatchInItem(LogicWarehouseBatchInDO mainEntity,
			LogicWarehouseBatchInItemDO itemEntity, User user)
			throws SyBaseException {
		Map<String, Boolean> isStorage=getStorageType();
		try{
			//增加仓库的库存
			LogicWarehouseDetailsDO lw = new LogicWarehouseDetailsDO();
			lw.setZd001BillCode(mainEntity.getZd001Code());
			lw.setZd002BillType(BillTypeConstant.BATCHIN);
			lw.setZd003WhId(mainEntity.getZd003WhId());
			lw.setZd003WhCode(mainEntity.getZd003WhCode());
			lw.setZd003WhName(mainEntity.getZd003WhName());
			lw.setZd004WhPositionId(null);
			lw.setZd004WhPositionCode(null);
			lw.setZd005MaterialsId(itemEntity.getZd002MaterId());
			lw.setZd005MaterialsCode(itemEntity.getZd002MaterCode());
			lw.setZd005MaterialsName(itemEntity.getZd002MaterName());
			lw.setZd006MaterialsSpec(itemEntity.getZd002MaterSpec());
			lw.setZd007MaterialsModel(itemEntity.getZd002MaterModel());
			lw.setZd008MaterialsQuanlity(itemEntity.getZd002MaterQuanlity());
			lw.setZd008MaterialsColor(itemEntity.getZd002MaterColor());
			lw.setZd009BasicUnit(itemEntity.getZd006Uint());
			lw.setZd011BasicQuantity(itemEntity.getZd003InQuantity());
			lw.setZd012Status(null);
			lw.setZd013Price(itemEntity.getZd007Price());
			lw.setZd014StockPrice(null);
			lw.setZd019Batch(Constants.SYS_DEFAULT_BATCH);
			lw.setZd020PiCode(itemEntity.getZd005PiCode());
			if(isStorage.get(mainEntity.getZd003WhId())){
				//是成品取客户的值 
				lw.setZd022ConsumerID(itemEntity.getZd004CustomerId());
				lw.setZd022ConsumerCode(itemEntity.getZd004CustomerCode());
				lw.setZd022ConsumerName(itemEntity.getZd004CustomerName());
			}else{
				//材料仓 取供应商
				lw.setZd022ConsumerID(mainEntity.getZd007SupplierId());
				lw.setZd022ConsumerCode(mainEntity.getZd007SupplierCode());
				lw.setZd022ConsumerName(mainEntity.getZd007SupplierName());
			}
			lw.setBizCreatorName(user.getName());
			lw.setBizCreatorDate(new Date());
			logicWarehouseInventoryService.updateWhAffstockQuantity(lw, user,true);
		}catch(Exception e){
			e.printStackTrace();
			throw new SyBaseException(GlobalResLoader.getOpfailed()+ e.getMessage());
		}
		
	}
	
}
